package com.hippoDocker.order.controller;

import com.hippoDocker.commons.entities.CommonResult;
import com.hippoDocker.commons.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @ClassName PaymentController
 * @Description TODO 客户端订单类
 * @Author hippoDocker
 * @Date 2022/5/30 1:04
 **/
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Resource
    private RestTemplate restTemplate;

//    public static final String PAYMENT_URL = "http://localhost:8001";
    public static final String PAYMENT_URL = "http://CLOUD-PROVIDER-PAYMENT";

    @GetMapping("/createPayment")
    public CommonResult createPayment(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment/createPayment", payment, CommonResult.class);
    }

    @GetMapping("/getPaymentById/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/getPaymentById/" + id, CommonResult.class);
    }

    /**
     * @description: TODO sleuth+zipkin演示
     * @param
     * @author: hippoDocker
     * @return:
     */
    @GetMapping("/zipkin")
    public String showZipkin(){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/zipkin",String.class);
    }


}
